import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:张熳
 * Date:2025-11-18
 * Time:22:14
 */
public class Test {
    public static void main(String[] args) {
        TestHeap testHeap = new TestHeap();
        //建大根堆
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);
        testHeap.createHeap();
        //升序排序
        testHeap.heapSort();
        System.out.println(Arrays.toString(testHeap.getElem()));//[15, 18, 19, 25, 27, 28, 34, 37, 49, 65]

        TestHeap testHeap1 = new TestHeap();
        //建小根堆
        int[] array1 = {27,15,19,18,28,34,65,49,25,37};
        testHeap1.initElem(array1);
        testHeap1.createHeap1();
        //降序排序
        testHeap1.heapSort1();
        System.out.println(Arrays.toString(testHeap1.getElem()));//[65, 49, 37, 34, 28, 27, 25, 19, 18, 15]
    }
    public static void main5(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);

        testHeap.createHeap();
        //堆顶元素的删除-大根堆调整
        System.out.println(testHeap.poll());//65

        //获取堆顶元素
        System.out.println(testHeap.peek());//49
    }
    public static void main4(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);

        testHeap.createHeap();
        testHeap.offer(80);
        System.out.println(Arrays.toString(testHeap.getElem()));//[80, 65, 34, 25, 49, 27, 19, 18, 15, 28, 37, 0,...]

        testHeap.createHeap1();
        testHeap.offer1(80);
        System.out.println(Arrays.toString(testHeap.getElem()));//[15, 18, 19, 25, 28, 34, 65, 49, 27, 37, 80, 0, ...]
    }
    public static void main3(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        //向上调整创建堆
        for (int i: array) {
            testHeap.offer1(i); //elem=[15,18,19,25,28,34,65,49,27,37]
        }
        //堆的插入(小根堆调整)
        testHeap.offer1(80);////elem=[15,18,19,25,28,34,65,49,27,37,80,0,0,0,0,0,0,0,0,0]
    }
    public static void main2(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        //向上调整创建堆
        for (int i = 0; i < array.length; i++) {
            testHeap.offer(array[i]); //elem=[65,49,34,27,37,19,28,15,25,18]
        }
        /*
        for (int j : array) {
            testHeap.offer(j); //elem=[65,49,34,27,37,19,28,15,25,18]
        }
        */
        //堆的插入(大根堆调整)
        testHeap.offer(80);//elem=[80,65,34,27,49,19,28,15,25,18,37,0,0,0,0,0,0,0,0,0]
        //testHeap.offer(8);
    }
    public static void main1(String[] args) {
        TestHeap testHeap = new TestHeap();
        int[] array = {27,15,19,18,28,34,65,49,25,37};
        testHeap.initElem(array);
        System.out.println(Arrays.toString(testHeap.getElem()));//[27, 15, 19, 18, 28, 34, 65, 49, 25, 37]
        //向下调整创建大根堆
        testHeap.createHeap();
        System.out.println(Arrays.toString(testHeap.getElem()));//[65, 49, 34, 25, 37, 27, 19, 18, 15, 28]
        //向下调整创建小根堆
        testHeap.createHeap1();
        System.out.println(Arrays.toString(testHeap.getElem()));//[15, 18, 19, 25, 28, 27, 34, 49, 65, 37]
    }
}
